#include <SDL2/SDL.h>
#include <fmt/format.h>
#include "../opengl/opengl.hpp"

int main(int argc, char **argv) {
    using namespace opengl;

    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    auto w = SDL_CreateWindow("", 30, 30, 30, 30, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
    auto ctx = SDL_GL_CreateContext(w);
    SDL_GL_MakeCurrent(w, ctx);
    init_opengl(opengl_config{.load_function = &SDL_GL_GetProcAddress});

    if (argc != 3) {
        fmt::println("Usage: {} [vs] [fs]", argv[0]);
        return 1;
    }
    program p({shader::from_file(shader::vertex_shader, argv[1]), shader::from_file(shader::fragment_shader, argv[2])});
    fmt::println("{}", p.get_error());

    SDL_GL_DeleteContext(ctx);
    SDL_DestroyWindow(w);
    return 0;
}